From: Alex Crichton Date: Thu, 24 Aug 2017 22:04:46 +0000 (-0700) Subject: Add infrastructure for nightly Cargo flags X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~7^2~6^2 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=f26fc37df087812397663483709c65ba64bd863f;p=cargo.git Add infrastructure for nightly Cargo flags --- diff --git a/src/bin/bench.rs b/src/bin/bench.rs index dcee0049e..f0921667c 100644 --- a/src/bin/bench.rs +++ b/src/bin/bench.rs @@ -35,6 +35,8 @@ pub struct Options { arg_args: Vec, flag_all: bool, flag_exclude: Vec, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -72,6 +74,7 @@ Options: --no-fail-fast Run all benchmarks regardless of failure --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo All of the trailing arguments are passed to the benchmark binaries generated for filtering benchmarks and generally providing options configuring how they @@ -99,7 +102,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; let ws = Workspace::new(&root, config)?; diff --git a/src/bin/build.rs b/src/bin/build.rs index b0ee43b4b..b40741092 100644 --- a/src/bin/build.rs +++ b/src/bin/build.rs @@ -33,6 +33,8 @@ pub struct Options { flag_frozen: bool, flag_all: bool, flag_exclude: Vec, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -69,6 +71,7 @@ Options: --message-format FMT Error format: human, json [default: human] --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo If the --package argument is given, then SPEC is a package id specification which indicates which package should be built. If it is not given, then the @@ -91,7 +94,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; let ws = Workspace::new(&root, config)?; diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index c7432905c..155d42b63 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -31,6 +31,8 @@ pub struct Flags { arg_args: Vec, flag_locked: bool, flag_frozen: bool, + #[serde(rename = "flag_Z")] + flag_z: Vec, } const USAGE: &'static str = " @@ -50,6 +52,7 @@ Options: --color WHEN Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo Some common cargo commands are (see all commands with --list): build Compile the current project @@ -149,7 +152,8 @@ fn execute(flags: Flags, config: &Config) -> CliResult { flags.flag_quiet, &flags.flag_color, flags.flag_frozen, - flags.flag_locked)?; + flags.flag_locked, + &flags.flag_z)?; init_git_transports(config); let _token = cargo::util::job::setup(); diff --git a/src/bin/check.rs b/src/bin/check.rs index 262e4aaf8..a89a3b579 100644 --- a/src/bin/check.rs +++ b/src/bin/check.rs @@ -39,6 +39,7 @@ Options: --message-format FMT Error format: human, json [default: human] --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo If the --package argument is given, then SPEC is a package id specification which indicates which package should be built. If it is not given, then the @@ -78,6 +79,8 @@ pub struct Options { flag_frozen: bool, flag_all: bool, flag_exclude: Vec, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub fn execute(options: Options, config: &Config) -> CliResult { @@ -88,7 +91,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; let ws = Workspace::new(&root, config)?; diff --git a/src/bin/clean.rs b/src/bin/clean.rs index 661425e9e..9e331dd64 100644 --- a/src/bin/clean.rs +++ b/src/bin/clean.rs @@ -16,6 +16,8 @@ pub struct Options { flag_release: bool, flag_frozen: bool, flag_locked: bool, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -35,6 +37,7 @@ Options: --color WHEN Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo If the --package argument is given, then SPEC is a package id specification which indicates which package's artifacts should be cleaned out. If it is not @@ -48,7 +51,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; let opts = ops::CleanOptions { diff --git a/src/bin/doc.rs b/src/bin/doc.rs index 517d2b6da..ec45feef1 100644 --- a/src/bin/doc.rs +++ b/src/bin/doc.rs @@ -27,6 +27,8 @@ pub struct Options { flag_frozen: bool, flag_locked: bool, flag_all: bool, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -57,6 +59,7 @@ Options: --message-format FMT Error format: human, json [default: human] --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo By default the documentation for the local package and all dependencies is built. The output is all placed in `target/doc` in rustdoc's usual format. @@ -78,7 +81,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; let ws = Workspace::new(&root, config)?; diff --git a/src/bin/fetch.rs b/src/bin/fetch.rs index 6b61ba7d6..8dce4633f 100644 --- a/src/bin/fetch.rs +++ b/src/bin/fetch.rs @@ -11,6 +11,8 @@ pub struct Options { flag_color: Option, flag_frozen: bool, flag_locked: bool, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -27,6 +29,7 @@ Options: --color WHEN Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo If a lockfile is available, this command will ensure that all of the git dependencies and/or registries dependencies are downloaded and locally @@ -43,7 +46,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; let ws = Workspace::new(&root, config)?; ops::fetch(&ws)?; diff --git a/src/bin/generate_lockfile.rs b/src/bin/generate_lockfile.rs index 60cb6c656..f6733768c 100644 --- a/src/bin/generate_lockfile.rs +++ b/src/bin/generate_lockfile.rs @@ -13,6 +13,8 @@ pub struct Options { flag_color: Option, flag_frozen: bool, flag_locked: bool, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -29,6 +31,7 @@ Options: --color WHEN Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo "; pub fn execute(options: Options, config: &Config) -> CliResult { @@ -37,7 +40,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; let ws = Workspace::new(&root, config)?; diff --git a/src/bin/git_checkout.rs b/src/bin/git_checkout.rs index 7dc9c5c98..ed020c7ef 100644 --- a/src/bin/git_checkout.rs +++ b/src/bin/git_checkout.rs @@ -11,6 +11,8 @@ pub struct Options { flag_color: Option, flag_frozen: bool, flag_locked: bool, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -27,6 +29,7 @@ Options: --color WHEN Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo "; pub fn execute(options: Options, config: &Config) -> CliResult { @@ -34,7 +37,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let Options { flag_url: url, flag_reference: reference, .. } = options; let url = url.to_url()?; diff --git a/src/bin/init.rs b/src/bin/init.rs index 50afe9bea..6d5c37185 100644 --- a/src/bin/init.rs +++ b/src/bin/init.rs @@ -15,6 +15,8 @@ pub struct Options { flag_vcs: Option, flag_frozen: bool, flag_locked: bool, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -38,6 +40,7 @@ Options: --color WHEN Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo "; pub fn execute(options: Options, config: &Config) -> CliResult { @@ -46,7 +49,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let Options { flag_bin, flag_lib, arg_path, flag_name, flag_vcs, .. } = options; diff --git a/src/bin/install.rs b/src/bin/install.rs index 10ea2d125..1e34ece16 100644 --- a/src/bin/install.rs +++ b/src/bin/install.rs @@ -31,6 +31,8 @@ pub struct Options { flag_rev: Option, flag_path: Option, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -66,6 +68,7 @@ Build and install options: --color WHEN Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo This command manages Cargo's local set of installed binary crates. Only packages which have [[bin]] targets can be installed, and all binaries are installed into @@ -103,7 +106,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let compile_opts = ops::CompileOptions { config: config, diff --git a/src/bin/login.rs b/src/bin/login.rs index a9d6b1a71..c41118cc3 100644 --- a/src/bin/login.rs +++ b/src/bin/login.rs @@ -15,6 +15,8 @@ pub struct Options { flag_color: Option, flag_frozen: bool, flag_locked: bool, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -31,6 +33,7 @@ Options: --color WHEN Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo "; @@ -39,7 +42,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let token = match options.arg_token.clone() { Some(token) => token, None => { diff --git a/src/bin/metadata.rs b/src/bin/metadata.rs index 081153530..9d52d610b 100644 --- a/src/bin/metadata.rs +++ b/src/bin/metadata.rs @@ -17,6 +17,8 @@ pub struct Options { flag_verbose: u32, flag_frozen: bool, flag_locked: bool, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -41,6 +43,7 @@ Options: --color WHEN Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo "; pub fn execute(options: Options, config: &Config) -> CliResult { @@ -48,7 +51,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let manifest = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; if options.flag_format_version.is_none() { diff --git a/src/bin/new.rs b/src/bin/new.rs index 7dbb00b96..9b0c97d95 100644 --- a/src/bin/new.rs +++ b/src/bin/new.rs @@ -15,6 +15,8 @@ pub struct Options { flag_vcs: Option, flag_frozen: bool, flag_locked: bool, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -38,6 +40,7 @@ Options: --color WHEN Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo "; pub fn execute(options: Options, config: &Config) -> CliResult { @@ -46,7 +49,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let Options { flag_bin, flag_lib, arg_path, flag_name, flag_vcs, .. } = options; diff --git a/src/bin/owner.rs b/src/bin/owner.rs index 587a968a6..438bb109d 100644 --- a/src/bin/owner.rs +++ b/src/bin/owner.rs @@ -14,6 +14,8 @@ pub struct Options { flag_list: bool, flag_frozen: bool, flag_locked: bool, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -34,6 +36,7 @@ Options: --color WHEN Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo This command will modify the owners for a package on the specified registry (or default). Note that owners of a package can upload new versions, yank old @@ -49,7 +52,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let opts = ops::OwnersOptions { krate: options.arg_crate, token: options.flag_token, diff --git a/src/bin/package.rs b/src/bin/package.rs index e4c4af449..8b88ba882 100644 --- a/src/bin/package.rs +++ b/src/bin/package.rs @@ -16,6 +16,8 @@ pub struct Options { flag_jobs: Option, flag_frozen: bool, flag_locked: bool, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -37,6 +39,7 @@ Options: --color WHEN Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo "; pub fn execute(options: Options, config: &Config) -> CliResult { @@ -44,7 +47,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; let ws = Workspace::new(&root, config)?; ops::package(&ws, &ops::PackageOpts { diff --git a/src/bin/pkgid.rs b/src/bin/pkgid.rs index f85741394..d69c982df 100644 --- a/src/bin/pkgid.rs +++ b/src/bin/pkgid.rs @@ -13,6 +13,8 @@ pub struct Options { flag_locked: bool, flag_package: Option, arg_spec: Option, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -30,6 +32,7 @@ Options: --color WHEN Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo Given a argument, print out the fully qualified package id specifier. This command will generate an error if is ambiguous as to which package @@ -58,7 +61,8 @@ pub fn execute(options: Options, options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let root = find_root_manifest_for_wd(options.flag_manifest_path.clone(), config.cwd())?; let ws = Workspace::new(&root, config)?; diff --git a/src/bin/publish.rs b/src/bin/publish.rs index 507496b46..d77957109 100644 --- a/src/bin/publish.rs +++ b/src/bin/publish.rs @@ -18,6 +18,8 @@ pub struct Options { flag_dry_run: bool, flag_frozen: bool, flag_locked: bool, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -41,6 +43,7 @@ Options: --color WHEN Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo "; @@ -49,9 +52,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; - - + options.flag_locked, + &options.flag_z)?; let Options { flag_token: token, diff --git a/src/bin/run.rs b/src/bin/run.rs index 58012cb34..64f30877d 100644 --- a/src/bin/run.rs +++ b/src/bin/run.rs @@ -24,6 +24,8 @@ pub struct Options { flag_frozen: bool, flag_locked: bool, arg_args: Vec, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -50,6 +52,7 @@ Options: --message-format FMT Error format: human, json [default: human] --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo If neither `--bin` nor `--example` are given, then if the project only has one bin target it will be run. Otherwise `--bin` specifies the bin target to run, @@ -66,7 +69,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; diff --git a/src/bin/rustc.rs b/src/bin/rustc.rs index 95f6d173b..fafa8632d 100644 --- a/src/bin/rustc.rs +++ b/src/bin/rustc.rs @@ -33,6 +33,8 @@ pub struct Options { flag_profile: Option, flag_frozen: bool, flag_locked: bool, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -68,6 +70,7 @@ Options: --message-format FMT Error format: human, json [default: human] --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo The specified target for the current package (or package specified by SPEC if provided) will be compiled along with all of its dependencies. The specified @@ -90,7 +93,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; diff --git a/src/bin/rustdoc.rs b/src/bin/rustdoc.rs index 82de14c00..6ff12689c 100644 --- a/src/bin/rustdoc.rs +++ b/src/bin/rustdoc.rs @@ -31,6 +31,8 @@ pub struct Options { flag_all_targets: bool, flag_frozen: bool, flag_locked: bool, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -66,6 +68,7 @@ Options: --message-format FMT Error format: human, json [default: human] --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo The specified target for the current package (or package specified by SPEC if provided) will be documented with the specified ... being passed to the @@ -85,7 +88,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; diff --git a/src/bin/search.rs b/src/bin/search.rs index 8a456d124..17b8ed3aa 100644 --- a/src/bin/search.rs +++ b/src/bin/search.rs @@ -14,6 +14,8 @@ pub struct Options { flag_frozen: bool, flag_locked: bool, arg_query: Vec, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -33,6 +35,7 @@ Options: --limit LIMIT Limit the number of results (default: 10, max: 100) --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo "; pub fn execute(options: Options, config: &Config) -> CliResult { @@ -40,7 +43,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let Options { flag_index: index, flag_host: host, // TODO: Depricated, remove diff --git a/src/bin/test.rs b/src/bin/test.rs index 39322feb5..b27421a2b 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -37,6 +37,8 @@ pub struct Options { flag_locked: bool, flag_all: bool, flag_exclude: Vec, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -76,6 +78,7 @@ Options: --no-fail-fast Run all tests regardless of failure --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo All of the trailing arguments are passed to the test binaries generated for filtering tests and generally providing options configuring how they run. For @@ -120,7 +123,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; let ws = Workspace::new(&root, config)?; diff --git a/src/bin/uninstall.rs b/src/bin/uninstall.rs index 619b029f5..69079265e 100644 --- a/src/bin/uninstall.rs +++ b/src/bin/uninstall.rs @@ -10,6 +10,8 @@ pub struct Options { flag_color: Option, flag_frozen: bool, flag_locked: bool, + #[serde(rename = "flag_Z")] + flag_z: Vec, arg_spec: String, } @@ -30,6 +32,7 @@ Options: --color WHEN Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo The argument SPEC is a package id specification (see `cargo help pkgid`) to specify which crate should be uninstalled. By default all binaries are @@ -42,7 +45,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let root = options.flag_root.as_ref().map(|s| &s[..]); ops::uninstall(root, &options.arg_spec, &options.flag_bin, config)?; diff --git a/src/bin/update.rs b/src/bin/update.rs index 1890ab7cc..a9a57312e 100644 --- a/src/bin/update.rs +++ b/src/bin/update.rs @@ -16,6 +16,8 @@ pub struct Options { flag_color: Option, flag_frozen: bool, flag_locked: bool, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -35,6 +37,7 @@ Options: --color WHEN Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo This command requires that a `Cargo.lock` already exists as generated by `cargo build` or related commands. @@ -63,7 +66,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; let update_opts = ops::UpdateOptions { diff --git a/src/bin/verify_project.rs b/src/bin/verify_project.rs index ea03bdd58..00127e1fe 100644 --- a/src/bin/verify_project.rs +++ b/src/bin/verify_project.rs @@ -17,6 +17,8 @@ pub struct Flags { flag_color: Option, flag_frozen: bool, flag_locked: bool, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub const USAGE: &'static str = " @@ -34,6 +36,7 @@ Options: --color WHEN Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo "; pub fn execute(args: Flags, config: &Config) -> CliResult { @@ -41,7 +44,8 @@ pub fn execute(args: Flags, config: &Config) -> CliResult { args.flag_quiet, &args.flag_color, args.flag_frozen, - args.flag_locked)?; + args.flag_locked, + &args.flag_z)?; let mut contents = String::new(); let filename = args.flag_manifest_path.unwrap_or("Cargo.toml".into()); diff --git a/src/bin/yank.rs b/src/bin/yank.rs index de48639ec..0526c4c4f 100644 --- a/src/bin/yank.rs +++ b/src/bin/yank.rs @@ -13,6 +13,8 @@ pub struct Options { flag_undo: bool, flag_frozen: bool, flag_locked: bool, + #[serde(rename = "flag_Z")] + flag_z: Vec, } pub static USAGE: &'static str = " @@ -32,6 +34,7 @@ Options: --color WHEN Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date + -Z FLAG ... Unstable (nightly-only) flags to Cargo The yank command removes a previously pushed crate's version from the server's index. This command does not delete any data, and the crate will still be @@ -47,7 +50,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_quiet, &options.flag_color, options.flag_frozen, - options.flag_locked)?; + options.flag_locked, + &options.flag_z)?; ops::yank(config, options.arg_crate, options.flag_vers, diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index 4a24024c1..51b82076c 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -63,8 +63,8 @@ macro_rules! features { impl Feature { $( pub fn $feature() -> &'static Feature { - fn get(features: &Features) -> &bool { - &features.$feature + fn get(features: &Features) -> bool { + features.$feature } static FEAT: Feature = Feature { name: stringify!($feature), @@ -73,6 +73,10 @@ macro_rules! features { &FEAT } )* + + fn is_enabled(&self, features: &Features) -> bool { + (self.get)(features) + } } impl Features { @@ -123,7 +127,7 @@ features! { pub struct Feature { name: &'static str, - get: fn(&Features) -> &bool, + get: fn(&Features) -> bool, } impl Features { @@ -173,7 +177,7 @@ impl Features { } pub fn require(&self, feature: &Feature) -> CargoResult<()> { - if *(feature.get)(self) { + if feature.is_enabled(self) { Ok(()) } else { let feature = feature.name.replace("_", "-"); @@ -196,6 +200,70 @@ impl Features { } } +/// A parsed represetnation of all unstable flags that Cargo accepts. +/// +/// Cargo, like `rustc`, accepts a suite of `-Z` flags which are intended for +/// gating unstable functionality to Cargo. These flags are only available on +/// the nightly channel of Cargo. +/// +/// This struct doesn't have quite the same convenience macro that the features +/// have above, but the procedure should still be relatively stable for adding a +/// new unstable flag: +/// +/// 1. First, add a field to this `CliUnstable` structure. All flags are allowed +/// to have a value as the `-Z` flags are either of the form `-Z foo` or +/// `-Z foo=bar`, and it's up to you how to parse `bar`. +/// +/// 2. Add an arm to the match statement in `CliUnstable::add` below to match on +/// your new flag. The key (`k`) is what you're matching on and the value is +/// in `v`. +/// +/// 3. (optional) Add a new parsing function to parse your datatype. As of now +/// there's an example for `bool`, but more can be added! +/// +/// 4. In Cargo use `config.cli_unstable()` to get a reference to this structure +/// and then test for your flag or your value and act accordingly. +/// +/// If you have any trouble with this, please let us know! +#[derive(Default, Debug)] +pub struct CliUnstable { + pub print_im_a_teapot: bool, +} + +impl CliUnstable { + pub fn parse(&mut self, flags: &[String]) -> CargoResult<()> { + if flags.len() > 0 && !nightly_features_allowed() { + bail!("the `-Z` flag is only accepted on the nightly channel of Cargo") + } + for flag in flags { + self.add(flag)?; + } + Ok(()) + } + + fn add(&mut self, flag: &str) -> CargoResult<()> { + let mut parts = flag.splitn(2, '='); + let k = parts.next().unwrap(); + let v = parts.next(); + + fn parse_bool(value: Option<&str>) -> CargoResult { + match value { + None | + Some("yes") => Ok(true), + Some("no") => Ok(false), + Some(s) => bail!("expected `no` or `yes`, found: {}", s), + } + } + + match k { + "print-im-a-teapot" => self.print_im_a_teapot = parse_bool(v)?, + _ => bail!("unknown `-Z` flag specified: {}", k), + } + + Ok(()) + } +} + fn channel() -> String { env::var("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS").unwrap_or_else(|_| { ::version().cfg_info.map(|c| c.release_channel) diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index 908899985..74187bc9c 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -9,6 +9,7 @@ use url::Url; use core::{Dependency, PackageId, Summary, SourceId, PackageIdSpec}; use core::{WorkspaceConfig, Features, Feature}; +use util::Config; use util::toml::TomlManifest; use util::errors::*; @@ -321,6 +322,15 @@ impl Manifest { Ok(()) } + + // Just a helper function to test out `-Z` flags on Cargo + pub fn print_teapot(&self, config: &Config) { + if let Some(teapot) = self.im_a_teapot { + if config.cli_unstable().print_im_a_teapot { + println!("im-a-teapot = {}", teapot); + } + } + } } impl VirtualManifest { diff --git a/src/cargo/core/mod.rs b/src/cargo/core/mod.rs index 2323b6c40..2eb0c608b 100644 --- a/src/cargo/core/mod.rs +++ b/src/cargo/core/mod.rs @@ -1,5 +1,5 @@ pub use self::dependency::Dependency; -pub use self::features::{Features, Feature}; +pub use self::features::{Features, Feature, CliUnstable}; pub use self::manifest::{EitherManifest, VirtualManifest}; pub use self::manifest::{Manifest, Target, TargetKind, Profile, LibKind, Profiles}; pub use self::package::{Package, PackageSet}; diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index c1931fc0a..894d2a7a2 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -232,6 +232,7 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>, } } else { let root_package = ws.current()?; + root_package.manifest().print_teapot(ws.config()); let all_features = resolve_all_features(&resolve_with_overrides, root_package.package_id()); generate_targets(root_package, profiles, mode, filter, &all_features, release)?; diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index e86877eae..359ec01ab 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -1,4 +1,4 @@ -use std::cell::{RefCell, RefMut, Cell}; +use std::cell::{RefCell, RefMut, Cell, Ref}; use std::collections::HashSet; use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::collections::hash_map::HashMap; @@ -12,7 +12,7 @@ use std::path::{Path, PathBuf}; use std::str::FromStr; use std::sync::{Once, ONCE_INIT}; -use core::Shell; +use core::{Shell, CliUnstable}; use core::shell::Verbosity; use jobserver; use serde::{Serialize, Serializer}; @@ -39,6 +39,7 @@ pub struct Config { frozen: Cell, locked: Cell, jobserver: Option, + cli_flags: RefCell, } impl Config { @@ -74,6 +75,7 @@ impl Config { Some((*GLOBAL_JOBSERVER).clone()) } }, + cli_flags: RefCell::new(CliUnstable::default()), } } @@ -371,7 +373,8 @@ impl Config { quiet: Option, color: &Option, frozen: bool, - locked: bool) -> CargoResult<()> { + locked: bool, + unstable_flags: &[String]) -> CargoResult<()> { let extra_verbose = verbose >= 2; let verbose = if verbose == 0 {None} else {Some(true)}; @@ -410,10 +413,15 @@ impl Config { self.extra_verbose.set(extra_verbose); self.frozen.set(frozen); self.locked.set(locked); + self.cli_flags.borrow_mut().parse(unstable_flags)?; Ok(()) } + pub fn cli_unstable(&self) -> Ref { + self.cli_flags.borrow() + } + pub fn extra_verbose(&self) -> bool { self.extra_verbose.get() } diff --git a/tests/cargo-features.rs b/tests/cargo-features.rs index 2f88f3867..fde2727d9 100644 --- a/tests/cargo-features.rs +++ b/tests/cargo-features.rs @@ -122,6 +122,54 @@ Caused by: ")); } +#[test] +fn nightly_feature_requires_nightly_in_dep() { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "b" + version = "0.0.1" + authors = [] + + [dependencies] + a = { path = "a" } + "#) + .file("src/lib.rs", "") + .file("a/Cargo.toml", r#" + [package] + name = "a" + version = "0.0.1" + authors = [] + im-a-teapot = true + cargo-features = ["test-dummy-unstable"] + "#) + .file("a/src/lib.rs", ""); + assert_that(p.cargo_process("build") + .masquerade_as_nightly_cargo(), + execs().with_status(0) + .with_stderr("\ +[COMPILING] a [..] +[COMPILING] b [..] +[FINISHED] [..] +")); + + assert_that(p.cargo("build"), + execs().with_status(101) + .with_stderr("\ +error: failed to load source for a dependency on `a` + +Caused by: + Unable to update [..] + +Caused by: + failed to parse manifest at `[..]` + +Caused by: + the cargo feature `test-dummy-unstable` requires a nightly version of Cargo, \ + but this is the `stable` channel +")); +} + #[test] fn cant_publish() { let p = project("foo") @@ -152,3 +200,60 @@ Caused by: but this is the `stable` channel ")); } + +#[test] +fn z_flags_rejected() { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "a" + version = "0.0.1" + authors = [] + im-a-teapot = true + cargo-features = ["test-dummy-unstable"] + "#) + .file("src/lib.rs", ""); + assert_that(p.cargo_process("build") + .arg("-Zprint-im-a-teapot"), + execs().with_status(101) + .with_stderr("\ +error: the `-Z` flag is only accepted on the nightly channel of Cargo +")); + + assert_that(p.cargo("build") + .masquerade_as_nightly_cargo() + .arg("-Zarg"), + execs().with_status(101) + .with_stderr("\ +error: unknown `-Z` flag specified: arg +")); + + assert_that(p.cargo("build") + .masquerade_as_nightly_cargo() + .arg("-Zprint-im-a-teapot"), + execs().with_status(0) + .with_stdout("im-a-teapot = true\n") + .with_stderr("\ +[COMPILING] a [..] +[FINISHED] [..] +")); +} + +#[test] +fn publish_rejected() { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "a" + version = "0.0.1" + authors = [] + cargo-features = ["test-dummy-unstable"] + "#) + .file("src/lib.rs", ""); + assert_that(p.cargo_process("package") + .masquerade_as_nightly_cargo(), + execs().with_status(101) + .with_stderr("\ +error: cannot package or publish crates which activate nightly-only cargo features +")); +}